package com.zut.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.zut.dao.CoachDao;
import com.zut.domain.Coach;
import com.zut.service.CoachService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class CoachServiceImpl implements CoachService {

    @Autowired
    private CoachDao coachDao;

    public List<Map<String, String>> getAll() {
        return coachDao.getAll();
    }

    public PageInfo<Map<String, String>> getAll(Integer pageNum, Integer pageSize) {
        List<Map<String, String>> list;
        PageHelper.startPage(pageNum, pageSize);
        list = coachDao.getAll();
        return new PageInfo<>(list);
    }

    public Coach getByNP(Coach coach) {
        return coachDao.getByNP(coach);
    }

    public Map<String, String> getById(String id) {
        Map<String, String> byId = coachDao.getById(id);
        return byId;
    }


    public boolean save(Coach coach) {
        return coachDao.insert(coach) > 0;

    }

    public Coach selectById(String id) {
        return coachDao.selectById(id);
    }

    public boolean deleteById(String id) {
        return coachDao.deleteById(id) > 0;
    }

    public boolean update(Coach coach) {
        return coachDao.update(coach) > 0;
    }

    public String getPlace(String id) {
        return coachDao.getPlace(id);
    }

    public String getPassword(String id) {
        return coachDao.getPassword(id);
    }

    public Map<String, String> getAvgGradeById(String id) {
        Map<String, String> avgGradeById = coachDao.getAvgGradeById(id);
        return avgGradeById;
    }

    public List<Coach> getBestCoach() {
        return coachDao.getBestCoach();
    }

    public boolean updatePassword(HashMap<String, String> map) {
        return coachDao.updatePwd(map) > 0;
    }


}
